﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Globalization;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for CancelAuctionManagerTest and is intended
    ///to contain all CancelAuctionManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CancelAuctionManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for CancelAuction
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(DataAccessException))]
        public void CancelAuctionTestFail()
        {
            long auctionedProductId = 0; // TODO: Initialize to an appropriate value
            CancelAuctionManager.CancelAuction(auctionedProductId);
        }

        /// <summary>
        ///A test for CancelAuction
        ///</summary>
        [TestMethod()]
        public void CancelAuctionTestSuccess()
        {
            Random rand = new Random();
            string email = "diroag" + rand.Next(500) + "@hotmail.com"; 
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("minombre", "miapellido", 'M',
                                         birthday, email, "qwerty12", "qwerty12", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("celular Sony Ericsson con todo incluido" + rand.Next(500), "120", "este celular tienes que comprarlo porque si no lo compras estoy chau viste o no viste", "Electronics", false, "Dollars", user.Id, "1");
            string initialAmount = "50"; 
            string currency = "Dollars"; 
            string productId = product.ProductId.ToString(CultureInfo.CurrentCulture); // TODO: Initialize to an appropriate value
            DateTime date = Convert.ToDateTime("04/05/2013 00:00:00"); // TODO: Initialize to an appropriate value
            int hour = 14; // TODO: Initialize to an appropriate value
            int minutes = 30; // TODO: Initialize to an appropriate value
            Auction actual;
            actual = AuctionRegistrationManager.RegisterAuction(email, initialAmount, currency, productId, date, hour, minutes);
            CancelAuctionManager.CancelAuction(Int64.Parse(productId,CultureInfo.CurrentCulture));
        }
    }
}
